#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;

const int N = 4010;

int n;
int q[N];

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    int T;
    scanf("%d", &T);
    while (T--){
        scanf("%d", &n);
        int x;
        for(int i = 1; i <= n; i ++){
            scanf("%d", &x);
            q[i] = q[i + n] = x;
        }

        int max1 = q[n] - q[1], max2 = q[n] - q[1], max3 = q[n] - q[1];
        for(int i = 1; i < n; i ++){
            max1 = max(max1, q[n] - q[i]);
        }

        for(int i = 2; i <= n; i ++){
            max2 = max(q[i] - q[1], max2);
        }

        for(int i = 1; i <= n; i ++){
            max3 = max(q[i + n - 1] - q[i], max3);
        }

        printf("%d\n", max(max(max1, max2), max3));
    }
    


    return 0;
}